package com.example.tv_webview;

import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.webkit.CookieManager;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.fragment.app.FragmentActivity;

import com.google.gson.Gson;
import com.google.gson.JsonArray;

import java.io.IOException;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

/*
 * Main Activity class that loads {@link MainFragment}.
 */
public class MainActivity extends FragmentActivity {

    private WebView webView;




    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //显示网页
        webView();
    }

    //显示百度网站
    private void webView() {
        webView = (WebView) findViewById(R.id.webview);
        webView.setWebViewClient(new WebViewClient());

        //清除登录网页产生的缓存
        clearWebViewCache();

        webView.loadUrl("https://www.cnpp.cn/pinpai/15.html");

        //webView.loadUrl("http://wine-plus.oss-cn-beijing.aliyuncs.com/2024/07/10/bc441a02d0624acc9cdc818d2d4c3e50.pdf");

        WebSettings webSettings = webView.getSettings();
        webSettings.setJavaScriptEnabled(true);
    }

    //清除登录网页产生的缓存
    private void clearWebViewCache() {
        webView.clearCache(true);
        CookieManager.getInstance().removeAllCookies(null);
    }

    @Override
    public void onBackPressed(){
        if (webView.canGoBack()){
            webView.goBack();
        }else {
            super.onBackPressed();
        }
    }



}